<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class CMasterModel extends CActiveRecord {

    public $isLogRequired = false;
    public $arBehavior = array();

    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    public function behaviors() {
        $arBehavior = array();
        if ($this->isLogRequired == 1) {
            $arBehavior['LoggableBehavior'] = 'application.modules.auditTrail.behaviors.LoggableBehavior';
        }
        return $arBehavior;
    }

    public function beforeSave() {

        $user = Yii::app()->getUser();

        if (parent::beforeSave()) {
            if ($this->isNewRecord) {
                $this->TIME_CREATED = CUtilities::getCurrentDateTimeDBFormat();
                $this->USER_CREATED = $user->id;
            } else {
                $this->USER_UPDATED = $user->id;
                $this->TIME_UPDATED = CUtilities::getCurrentDateTimeDBFormat();
            }

            return true;
        }
        else
            return false;
    }

}

?>
